<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="k" uri="/WEB-INF/k.tld"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>怀才进销存管理软件 - 销售前台</title>
		<jsp:include page="../inc.jsp"></jsp:include>
		<script type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
		<link href="../web/css/style.css" rel="stylesheet" type="text/css" />
		<SCRIPT language="JavaScript" type="text/javascript" src="../web/js/hdm.js"></SCRIPT>
		<SCRIPT>
		var calendar;
		var datagrid;
		var lastIndex;
		$(function(){
			calendar = $('#calendar').calendar({
				fit : true,
				current : new Date(),
				border : false,
				onSelect : function(date) {
					$(this).calendar('moveTo', new Date());
				}
			});
			
			datagrid = $('#datagrid').datagrid({
				url : '${pageContext.request.contextPath}/xsgl/salelistAction!noAuth_datagrid.html',
				title : '销售列表',
				iconCls : 'icon-save',
				pagination : true,
				pagePosition : 'bottom',
				pageSize : 10,
				pageList : [ 10, 20, 30, 40 ],
				fit : true,
				fitColumns : false,
				nowrap : false,
				border : false,
				idField : 'id',
				sortName : 'date',
				sortOrder : 'desc',
				checkOnSelect : false,
				selectOnCheck : false,
				singleSelect : true,
				columns : [ [  {
					title : '日期',
					field : 'date',
					width : 130,
					align:'center'
// 					,
// 					formatter : function(value, row, index) {
// 						return value.substring(0,10);
// 					}
				},{
					title : '编号',
					field : 'id',
					width : 120,
					align:'center',
					hidden: true
				}, {
					title : '单号',
					field : 'serial',
					width : 140,
					align:'center'
				},{
					title : '营业员',
					field : 'uusername',
					width : 80,
					align:'center'
				},{
					title : '会员编号',
					field : 'mid',
					width : 80,
					align : 'center',
					editor:{type:'numberbox'}
				},{
					title : '会员姓名',
					field : 'mname',
					width : 80,
					align:'center'
				},{
					title : '出货仓库',
					field : 'rname',
					width : 80,
					align:'center'
				},{
					title : '总金额',
					field : 'total',
					width : 80,
					align:'center'
				}, {
					title : '实付',
					field : 'realPay',
					width : 80,
					align:'center'
				}, {
					title : '抹零',
					field : 'wipeZero',
					width : 60,
					align:'center'
				}, {
					title : '找零',
					field : 'charge',
					width : 60,
					align:'center'
				}, {
					title : '使用积分',
					field : 'pointNum',
					width : 80,
					align:'center'
				}, {
					title : '现有积分',
					field : 'nowpoint',
					width : 80,
					align:'center'
				}, {
					title : '&nbsp;&nbsp;&nbsp;&nbsp;备注',
					field : 'remark',
					width : 200
				}, {
					title : '退货',
					field : 'returnGoods',
					width : 200
				}] ],
				toolbar : [ {
					text: '确定',
					iconCls:'icon-edit',
					handler:function(){
						$('#datagrid').datagrid('acceptChanges');
					}
				},{
					text : '保存',
					iconCls : 'icon-add',
					handler : function() {
						var mids = [];
						var rows = $('#datagrid').datagrid('getRows');
						for ( var i = 0; i < rows.length; i++) {
							if(rows[i].mname==null||rows[i].mname=='undefinded'){
								if(rows[i].mid!=null&&rows[i].mid!='undefinded'){
									mids.push(rows[i].id);
									mids.push(rows[i].mid);
								}
							}
						}
						$.post('${pageContext.request.contextPath}/xsgl/salelistAction!edit.html?model.mids='+mids,function(data){
							datagrid.datagrid('load');
						});
					}
				}, {
					text: '查看明细',
					iconCls:'icon-search',
					handler:function(){
						var rows = $('#datagrid').datagrid('getSelections');
						var id = rows[0].id;
						if(id!=null&&id!='undefinded'&&id!='null'){
							
							$.ajax({
								url : '${pageContext.request.contextPath}/xsgl/salelistAction!findSaleDetail.html?model.id='+id,
								dataType : 'JSON',
								type : 'POST',
								success:function(json){
								/*var json = $.parseJSON(d);
								alert(+"aaa");*/
								$('#mydialog').show(); 
								$('#mydialog').dialog({ 
								collapsible: false, 
								minimizable: false, 
								maximizable: false,
								closable:true,
								closed:false, 
								}); 

								/*
									$("#mytable").datagrid("insertRow", {
								        index: 0,
								        row: {}
								    });
								    */
								    closeMytableDialog();
								for(var i=0;i<json.length;i++){

										//alert(i+1);
									//closeMytableDialog();
										 $('#mytable').datagrid('appendRow',{
								            barcode:json[i].gbarcode,
								            type:json[i].gtype,
										    name:json[i].gname,
										    bname:json[i].bname, 
										    color:json[i].gcolor,
										    size:json[i].gsize,
										    number:json[i].number
									     });
									     
								}
								
								$("#mytable").datagrid({
									onDblClickRow:function(rowIndex, rowData){ 
										top.closeMytableDialog();
									}
								});
								}
							});
						}
					}
				}],
				onClickRow:function(rowIndex){
				if(lastIndex != rowIndex){
					$('#datagrid').datagrid('endEdit', lastIndex);
					$('#datagrid').datagrid('beginEdit', rowIndex);
					lastIndex = rowIndex;
				}else{
					$('#datagrid').datagrid('endEdit', lastIndex);
					$('#datagrid').datagrid('beginEdit', rowIndex);
					lastIndex = rowIndex;
				}
			 }			

			 });
			_search();
		});
		
		function logout(){
			sy.messagerConfirm('请确认', '您确定要退出前台销售？', function(r) {
				if(r){
					$.ajax({
						url : '${pageContext.request.contextPath}/loginAction!logout.html',
						type : 'get',
						success:function(){
							self.location.reload();
							if(window.opener){
								opener.location = opener.location;
							}
							window.close();
						}
					});
				}
			});
		}
		
		function _search() {
			datagrid.datagrid('load', sy.serializeObject($('#searchForm')));
			$('#searchForm').form('submit', {
			url : '${pageContext.request.contextPath}/xsgl/salelistAction!noAuth_datagridTotal.html',
			type : "POST",
			success : function(d){
				var json = $.parseJSON(d);
				//alert("json");
				$('#sjxszs').html(json.sjxszs);
				$('#xsthsl').html(json.xsthsl);
				$('#xszje').html(json.xszje.toFixed(2));
				$('#yhzje').html((json.yhzje).toFixed(2)); 
				$('#thzje').html((json.thzje).toFixed(2));
			}
		});
		}
		
		function cleanSearch() {
			datagrid.datagrid('load', {});
			$('#searchForm input').val(''); 
			$("#rid").val('');
			$("#uid").val('');
			_search();
		}
		
		function closeMytableDialog() { 
			$("#mytable").datagrid('loadData',{total:0,rows:[]});					
			/*$('#mydialog').dialog({
				closed:true,
			 });*/
		} 
		
		</SCRIPT>
	</head>

	<body>
		<div class="top">
			<div class="logo">
				<img src="../web/imgs/htlogo.jpg" width="480" height="47" />
			</div>
			<div class="right">
				欢迎您！${sessionInfo.loginName} [${sessionInfo.roleNames}]
				<a href="javascript:void(0)" onclick="logout()">退出登录</a>
				<!-- 
					<a href="#">修改密码</a>
				 -->
			</div>
		</div>
		<div class="content">
			<div class="right">
				<!--日历标题-->
				<div class="title">
					<img src="../web/imgs/pic1.gif" width="6" height="6" />
					日历
				</div>
				<!--/日历标题-->
				<!--日历-->
				<div style="height:180px;">
					<div id="calendar"></div>
				</div>
				<!--/日历-->
				<!--公告+提醒-->
				<div class="title">
					<ul>
						<li id="cp1" class="cpover" onMouseOver="setTab_('cp',1,5,'cpover')">
							公告<span class="tabRefresh"><a href="javascript:void(0);" onclick="javascript:document.frames('announcementIframe').location.reload()" class="icon-mini-refresh"></a></span>
						</li>
						<li id="cp2" onMouseOver="setTab_('cp',2,5,'cpover')">
							系统提醒<span class="tabRefresh"><a href="javascript:void(0);" onclick="javascript:document.frames('warnIframe').location.reload()" class="icon-mini-refresh"></a></span>
						</li>
					</ul>
				</div>
				<div class="conts">
					<div id="cp_con1">
						<iframe width="100%" height="400px;" scrolling="auto" frameborder="0" onload="javascript:void(0);" name="announcementIframe" id="announcementIframe" src="${pageContext.request.contextPath}/qtmk/announcementAction!noAuth_tabAnnounce.html"></iframe>
					</div>
					<div id="cp_con2" style="display: none;">
						<iframe width="100%" height="400px;" scrolling="no"  frameborder="0" onload="javascript:void(0);" name="warnIframe" id="warnIframe" src="${pageContext.request.contextPath}/qtmk/remindWarnAction!noAuth_tabRemindWarn.html"></iframe>
					</div>
				</div>
				<!--/公告+提醒-->
			</div>
			<div class="left">
				<div class="nav">
					<ul>
						<k:security key="XSGL_QTXS">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/sale.html">
								<img src="${pageContext.request.contextPath}/web/imgs/navxsgl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_XSTH">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/saleReturn.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-xsth.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_KCCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/amount.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-kcgl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_HYGL">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/member.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-hygl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_RJQS">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/settlement.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-rjqs.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_XSJLCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/salelist.html">
								<img src="../web/imgs/navxsglcx.jpg"  height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_THJLCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/saleReturnlist.html">
								<img src="../web/imgs/navthglcx.jpg" height="35" /> 
							</a>
						</li>
						</k:security>
					</ul>
				</div>
				<div class="cont">
					<div style="height: 120px; overflow: hidden;">
						<form id="searchForm">
							<table  style="width: 100%; height: 100%;">
								<tr>
									<th>所属仓库</th>
									<td>
										<select id="rid" name="rid" class="width1" id="rid" style="width: 200px;">
										<option value="">--请选择--</option>
											<c:forEach items="${VRepertories}" var="VRepertory">
												<option value='${VRepertory.id }'>${VRepertory.name }</option>
											</c:forEach>
										</select>
									</td>
									<th>营&nbsp;业&nbsp;员</th>
									<td>
										<select id="uid" name="uid" style="width: 200px;" id="uid">
											<option value=''>--请选择--</option>
											<c:forEach items="${VUsers}" var="VUser">
												<option value="${VUser.id }">${VUser.username }</option>
											</c:forEach>
										</select>
									</td>
								</tr>
								<tr>
									<th>开始时间</th>
									<td><input name="beginDate" style="width: 200px;" onClick="WdatePicker()"  class="input1"/></td>
									<th>结束时间</th>
									<td><input name="endDate" style="width: 200px;" onClick="WdatePicker()"  class="input1"/></td>
								</tr>
								<tr>
									<th>会员姓名</th>
									<td><input name="mSerial" style="width: 200px;"  class="input1"/></td>
									<th>商品款号</th>
									<td><input name="gtype" style="width: 200px;"  class="input1"/></td>
									
								</tr>
								<tr>
									<td colspan="4" align="center" style=" padding:2px 0 0px 400px;">
										<a href="javascript:void(0);" class="button2 dis_block fl m_l" onclick="_search();">搜索</a>
										<a href="javascript:void(0);" class="button3 dis_block fl m_l" onclick="cleanSearch();">取消</a>
									</td>
								</tr>
							</table>
						</form>
					</div>
					<div style="overflow: hidden;height:460px;">
						<table id="datagrid"></table>
					</div>
					<div data-options="region:'south',border:false"
					align="center" 	style="background:#F2F2F2; height: 25px">
							实际销售总数量:<span id="sjxszs">0</span>	&nbsp;&nbsp;
							实际销售总金额:<span  id="xszje">0.00</span>&nbsp;&nbsp;	&nbsp;&nbsp;
							销售退货数量:<span id="xsthsl">0</span>	&nbsp;&nbsp;
							实际退货总金额:<span  id="thzje">0.00</span>&nbsp;&nbsp;	&nbsp;&nbsp;
							优惠总金额:<span id="yhzje">0.00</span>&nbsp;&nbsp;&nbsp;&nbsp;
<!-- 							吊牌价总金额:<span id="dpzje" >0.00</span> -->
					</div>
				</div>
			</div>
			
		</div>
		<br><br><br>
		<div id="mydialog" style="display:none;padding:5px;width:600px;height:auto;min-height:150px;max-height:200px;overflow-y:scrooll;" title="查看销售明细">		 		
		<table id="mytable" class="easyui-datagrid" style="height:auto"  data-options="iconCls: 'icon-edit',singleSelect: true"> 
		        <thead>
		            <tr>
		            	<th data-options="field:'barcode',width:130">商品条码</th>  
		            	<th data-options="field:'type',width:80">款号</th>  
	                 	 <th data-options="field:'name',width:90">商品名称</th> 
	                 	<th data-options="field:'bname',width:70">品牌</th> 
                   		<th data-options="field:'color',width:60,align:'center'">颜色</th>
                   		<th data-options="field:'size',width:60,align:'center'">尺码</th>
                   		<th data-options="field:'number',width:60,align:'center'">购买数量</th>
		            </tr>
		        </thead>
		    </table>
		</div> 
		<div class="foot">
			Copyright @ 2013
			<a style="color:#FFFFFF; text-decoration:none;" target="_blank" href="http://www.miitbeian.gov.cn">浙ICP备13002014号-1</a>
			<br>
			杭州怀才商贸有限公司 服务电话：0571-28030726
		</div>
	</body>
</html>
